package com.jeeplus.modules.api;

import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.modules.annotation.TokenValidate;
import com.jeeplus.modules.api.utils.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api/test")
public class TokenController {
    @Autowired
    private JwtUtils jwtUtils;
    @PostMapping("/login")
    public Map<String,Object> login(String userName){
        Map<String,Object> concurrentMap=new HashMap<>(16);
        concurrentMap.put("username",userName);
        return jwtUtils.generateToken(concurrentMap);
    }

    @TokenValidate
    @GetMapping("/getData")
    public AjaxJson test(){
        AjaxJson ajaxJson = new AjaxJson();
        ajaxJson.setCode(0);
        ajaxJson.setMsg("ok");
        return ajaxJson;
    }
}